package com.epfresh.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CarCntResponse {

    /* "promotionCnt" : [ {
        "id" : 2,
                "type" : null,
                "idAndType" : null,
                "shoppingCarId" : null,
                "productId" : null,
                "promotionItemId" : null,
                "cnt" : 2.0
    } ]*/

    private Map<String , String >merMsgMap;

    public Map<String, String> getMerMsgMap() {
        return merMsgMap;
    }

    public void setMerMsgMap(Map<String, String> merMsgMap) {
        this.merMsgMap = merMsgMap;
    }

    private List<CarCnt> categoryCnt;

    private List<CarCnt> specCnt;

    private int shoppingCarCnt;
    private List<CarCnt> topCategoryCnt;
    private List<CarCnt> promotionCnt;

    private Map<String, Double> mapProduct;
    private Map<String, Double> mapCategory;
    private Map<String, Double> mapTopCategory;
    private Map<String, Double> mapPromotionCnt;

    private Map<String, String> mapShopingCarId;


    public List<CarCnt> getPromotionCnt() {
        return promotionCnt;
    }

    public void setPromotionCnt(List<CarCnt> promotionCnt) {
        this.promotionCnt = promotionCnt;
    }

    public void init() {
        if (specCnt != null && specCnt.size() > 0) {
            if (mapProduct == null) {
                mapProduct = new HashMap<>();
            }
            if (mapShopingCarId == null) {
                mapShopingCarId = new HashMap<>();
            }
            if (merMsgMap == null) {
                merMsgMap = new HashMap<>();
            }
            for (int i = 0; i < specCnt.size(); i++) {

                CarCnt carCnt = specCnt.get(i);
                mapProduct.put(carCnt.getProductIdPlus(), carCnt.getCnt());
                mapShopingCarId.put(carCnt.getProductIdPlus(), carCnt.getShoppingCarId());
                merMsgMap.put(carCnt.getProductIdPlus(),carCnt.getMerMsg());
            }
        }
        mapPromotionCnt = initListId(promotionCnt, mapPromotionCnt);

        mapCategory = initList(categoryCnt, mapCategory);
        mapTopCategory = initList(topCategoryCnt, mapTopCategory);

    }

    private Map<String, Double> initList(List<CarCnt> specCnt, Map<String, Double> mapProduct) {
        if (specCnt != null && specCnt.size() > 0) {
            if (mapProduct == null) {
                mapProduct = new HashMap<>();
            }
            for (int i = 0; i < specCnt.size(); i++) {

                CarCnt carCnt = specCnt.get(i);
//                mapProduct.put(carCnt.getIdPlus(), carCnt.getCnt());
                mapProduct.put(carCnt.getId(), carCnt.getCnt());

            }
        }

        return mapProduct;
    }
    private Map<String, Double> initListId(List<CarCnt> specCnt, Map<String, Double> mapProduct) {
        if (specCnt != null && specCnt.size() > 0) {
            if (mapProduct == null) {
                mapProduct = new HashMap<>();
            }
            for (int i = 0; i < specCnt.size(); i++) {

                CarCnt carCnt = specCnt.get(i);
                mapProduct.put(carCnt.getId(), carCnt.getCnt());

            }
        }

        return mapProduct;
    }

    public List<CarCnt> getCategoryCnt() {
        return categoryCnt;
    }

    public void setCategoryCnt(List<CarCnt> categoryCnt) {
        this.categoryCnt = categoryCnt;
    }

    public List<CarCnt> getspecCnt() {
        return specCnt;
    }

    public void setspecCnt(List<CarCnt> specCnt) {
        this.specCnt = specCnt;
    }

    public int getShoppingCarCnt() {
        return shoppingCarCnt;
    }

    public void setShoppingCarCnt(int shoppingCarCnt) {
        this.shoppingCarCnt = shoppingCarCnt;
    }

    public List<CarCnt> getTopCategoryCnt() {
        return topCategoryCnt;
    }

    public void setTopCategoryCnt(List<CarCnt> topCategoryCnt) {
        this.topCategoryCnt = topCategoryCnt;
    }



    public void putGoodsCount(String key, Double value) {
        if (mapProduct == null) {
            mapProduct = new HashMap<>();
        }
        mapProduct.put(key, value);
    }
    public double getGoodsCount(String id) {
        double cnt = 0;
        if (mapProduct != null) {
            Double aDouble = mapProduct.get(id);
            if (aDouble != null) {
                return aDouble;
            }
        }

        return cnt;
    }

    public void putShopingCarId(String key, String value) {
        if (mapShopingCarId == null) {
            mapShopingCarId = new HashMap<>();
        }
        mapShopingCarId.put(key, value);
    }

    public String getShopingCarId(String id) {
        String msg = "";
        if (mapShopingCarId != null) {
            msg = mapShopingCarId.get(id);
        }
        return msg;
    }

    public String getMsg(String id) {
        String msg = "";
        if (merMsgMap != null) {
            msg = merMsgMap.get(id);
        }
        return msg;
    }


    public void putCategoryCount(String key, Double value) {
        if (mapCategory == null) {
            mapCategory = new HashMap<>();
        }
        mapCategory.put(key, value);
    }

    public double getCategoryCount(String id) {
        double cnt = 0;
        if (mapCategory != null) {
            Double aDouble = mapCategory.get(id);
            if (aDouble != null) {
                return aDouble;
            }
        }

        return cnt;
    }
    public void putPromotionCount(String key,Double value) {
        if (mapPromotionCnt == null) {
            mapPromotionCnt = new HashMap<>();
        }
        mapPromotionCnt.put(key, value);
    }
    public double getPromotionCount(String id) {
        double cnt = 0;
        if (mapPromotionCnt != null) {

            Double aDouble = mapPromotionCnt.get(id);
            if (aDouble != null) {
                return aDouble;
            }
        }

        return cnt;
    }

    public void putTopCategoryCount(String key, Double value) {
        if (mapTopCategory == null) {
            mapTopCategory = new HashMap<>();
        }
        mapTopCategory.put(key, value);
    }

    public double getTopCategoryCount(String id) {
        double cnt = 0;
        if (mapTopCategory != null) {
            Double aDouble = mapTopCategory.get(id);
            if (aDouble != null) {
                return aDouble;
            }
        }

        return cnt;
    }
}
